label_array=newArray();
filename_array=newArray(); areas_array=newArray();//set up empty arrays for values from all images
files=getFileList(dir1);//list the files in the directorydir1=getDirectory("Choose Directory");//Set source directory
path=dir1+files[i];//joing file name and directory to make a complete path
open(path);//open file using the path
rename("Original");//rename to give uniform names to each open image
run("Stack to Images");//Split the stack into individual images
selectWindow("Original-0001");//select channel 1 (DAPI)for (i = 0; i < files.length; i++) {//Create a loop with as many iterations as there are filenames
run("Command From Macro", "command=[de.csbdresden.stardist.StarDist2D], args=['input':'Original-0001', 'modelChoice':'Versatile (fluorescent nuclei)', 'normalizeInput':'true', 'percentileBottom':'1.0', 'percentileTop':'99.8', 'probThresh':'0.5', 'nmsThresh':'0.4', 'outputType':'Both', 'nTiles':'1', 'excludeBoundary':'2', 'roiPosition':'Automatic', 'verbose':'false', 'showCsbdeepProgress':'false', 'showProbAndDist':'false'], process=[false]");
//Segment with Stardist
area=Table.getColumn("Area");//assign area values to variable
label=Table.getColumn("Label");//assign label values to variablerun("Analyze Regions", "area");//Calculate areas
areas_array=Array.concat(areas_array,area);//concatinate image variables to an an array for all the images
label_array=Array.concat(label_array,label);//concatinate image variables to an an array for all the images
filename_array=Array.concat(filename_array,files[i]);
}for (j = 0; j < area.length; j++) {//loop adding image filename to the filename_array once for every label measured
close("*");//close all images
} close("Label-Morphometry");//close image results table
Table.showArrays("Areas_Table", filename_array, label_array, areas_array); //compose a results table with all the areas